<template>
  <div class="Department">
    <el-main>
      <div>
        <el-form ref="form" :model="form" label-width="80px">
          <el-form-item label="资产分类:" prop="assetTypeId">
            <el-col :span="7">
              <div class="grid-content bg-purple">
                <el-select v-model="form.assetTypeId" @change="consolelog1" placeholder="资产类别">
                  <el-option
                    v-for="item in list1"
                    :key="item.id"
                    :label="item.name"
                    :value="item.id"
                  ></el-option>
                </el-select>
              </div>
            </el-col>
            <el-col :span="6">
              <div class="grid-content bg-purple">
                <el-button type="primary" icon="el-icon-document" @click="ExportAssetReportByDept">导出</el-button>
              </div>
            </el-col>
          </el-form-item>
        </el-form>
      </div>
      <el-table
        ref="multipleTable"
        :data="tableData3"
        border
        stripe
        height="400"
        tooltip-effect="dark"
        style="width: 100%"
        @selection-change="handleSelectionChange"
      >
        <!-- <el-table-column type="selection" width="55"></el-table-column> -->
        <!-- <el-table-column prop="id" label="编号" style="width: 25%"></el-table-column> -->
        <el-table-column prop="name" label="部门名称" style="width: 25%"></el-table-column>
        <el-table-column prop="count" label="资产数量" style="width: 25%"></el-table-column>
        <el-table-column prop="amount" label="资产金额(元)" style="width: 25%"></el-table-column>
      </el-table>
      <br>
      <!-- <div class="block">
        <el-row :gutter="20">
          <el-col :span="4">
            <div class="grid-content bg-purple">
              <span class="demonstration">已选择{{this.assetList.length}}条</span>
            </div>
          </el-col>
          <el-col :span="10">
            <div class="grid-content bg-purple">
              <el-pagination
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :current-page="currentPage4"
                :page-sizes="[10, 20, 30, 40]"
                :page-size="10"
                layout="prev, pager, next, sizes, jumper"
                :total="400"
              ></el-pagination>
            </div>
          </el-col>
        </el-row>
      </div> -->
    </el-main>
  </div>
</template>
<script>
import { axiosPost, axiosGet,requestUrl } from "@/api/index.js";
export default {
  data() {
    return {
      form: {
        name: "",
        count: "",
        amount: ""
      },
      total: 0,
      page: 1,
      pageSize: 10,
      assetTypeId: "", //选中的部门的id
      rules: {
        statement: [
          { required: true, message: "请选择资产分类", trigger: "change" }
        ]
      },
      tableData3: [],
      /* currentPage1: 5,
      currentPage2: 5,
      currentPage3: 5,
      currentPage4: 1, */
      assetList: [],
      list1: []
    };
  },
  beforeMount() {
    //资产类别接口
    // console.log("-----------调用GetAssetTypeList");
    axiosGet("Asset/GetAssetTypeList", null).then(res => {
      if (res.status === 200 && res.data.success) {
        this.list1 = res.data.data;
        // console.log("-----------.GetAssetTypeList   :" + res.data.data);
      }
    });
    //调用获取资产部门列表接口
    this.getAssetList();
  },
  methods: {
    toggleSelection(rows) {
      if (rows) {
        rows.forEach(row => {
          this.$refs.multipleTable.toggleRowSelection(row);
        });
      } else {
        this.$refs.multipleTable.clearSelection();
      }
    },
    handleSelectionChange(val) {
      this.assetList = val;
    },
    handleSizeChange(val) {
      // console.log(`每页 ${val} 条`);
      this.pageSize = val;
      this.getAssetList();
    },
    handleCurrentChange(val) {
      // console.log(`当前页: ${val}`);
      this.page = val;
      this.getAssetList();
    },
    consolelog1() {
      // console.log(this.form.assetTypeId);
      this.assetTypeId = this.form.assetTypeId;
      this.getAssetList();
    },
    getAssetList: function() {
      //获取资产部门列表
      var bean = {
        page: this.page,
        pageSize: this.pageSize,
        assetTypeId: this.assetTypeId
      };
      axiosGet("/Asset/GetAssetCountByOrganization", bean).then(res => {
        if (res.status == 200 && res.data.success) {
          this.tableData3 = res.data.data.list;
          /* console.log(
            "-----------.GetAssetCountByOrganization   :" + res.data.data
          ); */
        }
      });
    },
    //导出部门汇总
    ExportAssetReportByDept: function(){
      var bean = {
        page: this.page,
        pageSize: this.pageSize,
        assetTypeId: this.assetTypeId
      };
     /*  axiosGet("/Asset/ExportAssetReportByDept", bean).then(res => {
        if (res.status == 200 && res.data.success) {
          // this.tableData3 = res.data.data.list;
        }
      }); */
      window.location.href = requestUrl + "Asset/ExportAssetReportByDept";
    }
  }
};
</script>
<style lang="scss" scoped>
.Department {
  height: 100%;
}
</style>
